package engine.display.newAttack
{	
	import engine.GameData;
	import engine.control.Base64;
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.display.AttAckMsgCacheLogic;
	import engine.display.Story.StoryMoveUI;
	import engine.display.newAttack.vo.AttackVo;
	import engine.display.newAttack.vo.BoutVo;
	import engine.display.newAttack.vo.DamageVo;
	import engine.display.newAttack.vo.DropVo;
	import engine.display.newAttack.vo.FightInfoVo;
	import engine.display.newAttack.vo.FightPetInfoVo;
	import engine.display.newAttack.vo.FlowVo;
	import engine.display.newAttack.vo.PrizeVo;
	import engine.event.CustomEvent;
	import engine.event.RoleEffectEvent;
	import engine.event.SceneEvent;
	import engine.event.SoundEvent;
	import engine.flag.GameDefine;
	import engine.logic.ArrowGuideLogic;
	import engine.logic.walk.WalkLogic;
	import engine.logic.walk.WalkManager;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.newUi.ActionEctypeResultLogic;
	import engine.newUi.ActionResultLogic;
	import engine.newUi.CurrencyResultLogic;
	import engine.newUi.DuplicatesLogic;
	import engine.newUi.FactionBossUI;
	import engine.newUi.TaskTrackingUI;
	import engine.newUi.TopPlayerLogic;
	import engine.newUi.UpNoticeLogic;
	import engine.newUi.WarfareLogic;
	import engine.newUi.WorldBossBloodUI;
	import engine.scene.SceneChangeManager;
	import engine.scene.SceneManager;
	import engine.scene.player.BasePlayerModel;
	import engine.scene.player.NpcModel;
	import engine.scene.player.RoleModel;
	import engine.ui.MainUIManager;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.events.IEventDispatcher;
	import flash.events.MouseEvent;
	import flash.utils.setTimeout;
	
	import newx.StageInfo;
	import newx.com.config.StaticIni;
	import newx.com.control.button.NxButton;
	import newx.com.loader.SwfLoader;
	import newx.utils.debug.IO;
	
	/**
	 * 主战斗逻辑 
	 * @author lw
	 * 
	 */
	public class AttackLogic
	{		
		private static	 var _self	:	AttackLogic;
		
		private var _model			:	ModelLocator;
		
		private var _attackScene	:	AttackSceneView;
		
		private var _fightLogic	: 	FightLogic;
		
		private var _sceneMask		:	Shape;
		
		private var _effectMask	:	Shape;
			
		private var _fighting		:	Boolean;
		
		private var _cloneXml		:	XML;
		
		private var _attackArr		:	Array 	= 	[];
		
		private var _exp			: 	int;
		
		private var _experience	:	int; //阅历
		
		private var _dropList		:	Array	=	[];
		
		private var _pvpPrize		: 	Array	=	[];
		
		private var _pvpPrizeList	:	Array	=	[];
		
		private var _attackVo		: 	AttackVo;
		
		private var _isKillFight	: 	Boolean;
		
		private var _sceneModel	:	String;
		
		private var _isVideo		:	Boolean;
		
		private var _killFightBtn	:	NxButton;
		
		private var _sceneManager	:	SceneManager;
		
		private var _role			:	RoleModel;
		
		private var _attackType	:	int =0;	
		
		private var _porte:CustomMsgEvent;
		/**用于战斗播放出错之后记录日志**/
		public var  _catchAttackStr:String ;
		
		//当前竞技场战报
		private var _currWarfar:String;
		
		public function get attackVo():AttackVo
		{
			return _attackVo;
		}

		public static function getInstance():AttackLogic
		{
			if ( _self == null )
			{
				_self = new AttackLogic();
			}
			return _self;
		}
		
		public function AttackLogic(target:IEventDispatcher=null)
		{
			init();
			
			initMask();
		}
		
		public function get AttackSceneModel():String
		{
			return _sceneModel;
		}
		private function initMask():void
		{
			_sceneMask	=	new Shape();
			
			_sceneMask.graphics.beginFill(0xFF8800,.5);
			_sceneMask.graphics.drawRect(0,0,SceneChangeManager.attackSceneViewWidth,SceneChangeManager.attackSceneViewHeight);
			_sceneMask.graphics.endFill();
			_attackScene.addChild(_sceneMask);
			_attackScene.mask = _sceneMask;
			
			_effectMask	=	new Shape();
			_effectMask.graphics.beginFill(0xFF8800,.5);
			_effectMask.graphics.drawRect(0,0,SceneChangeManager.attackSceneViewWidth,SceneChangeManager.attackSceneViewHeight);
			_effectMask.graphics.endFill();
			_attackScene.addChild(_effectMask);
			
			_sceneMask.visible = _effectMask.visible = false;
			
			
//			StageInfo.effectSpace.mask = _mask;
			
			_sceneMask.visible = false;
		}
		
		private function init():void
		{
			_killFightBtn = new NxButton();
			_killFightBtn.skin = "Button_25";
			_killFightBtn.label="";
			_killFightBtn.width = 120;
			_killFightBtn.height = 55;
			_killFightBtn.x = 580; 
			_killFightBtn.y = 700 ;
			_killFightBtn.addEventListener( MouseEvent.CLICK, onKillFightClick );
			
			_model			=	ModelLocator.getInstance();
			
			_sceneManager	=	SceneManager.getInstance();
			
			//战斗场景初始化
			_attackScene	=	new AttackSceneView();
			_attackScene.addEventListener( AttackSceneView.PLAYERS_INIT_OVER, onStartFight );
			
			_fightLogic		=	new FightLogic( _attackScene );
			_fightLogic.addEventListener( FightLogic.FIGHT_OVER, fightOver );
			
			ActionEctypeResultLogic.getInstance().setFunc( 
			function():void
			{
				leaveAttackScene();
				AttAckMsgCacheLogic.getInstance().sendAttackMsg();
				SystemSender.getInstance().CustomMsg( CustomToServerFlag.CLIENT_CUSTOMMSG_FB_LEAVE );
				TaskTrackingUI.getInstance().autoLink();
			},
			function():void
			{
				DuplicatesLogic.getInstance().againIntoFb();
				GameData.Role.resetPoint( false );
			} );
			
			ActionResultLogic.getInstance().setFunc( function():void
			{
				
				if (fightwarfter.length<=0)
				{
					SystemSender.getInstance().CustomMsg( CustomToServerFlag.CLIENT_CUSTOMMSG_FB_END_CALCULATE );
				}
				leaveAttackScene();
				AttAckMsgCacheLogic.getInstance().sendKissBossMsg()
				
				if( GameData.SceneType == GameDefine.SceneType_WorldBossScene)
				{//boos战需要清缓存消息
					AttAckMsgCacheLogic.getInstance().sendAttackMsg();
				}
				
				//要去判断是否杀死了boos，杀死了，才能发送弹副本界面
			}, againFight );
			
			CurrencyResultLogic.getInstance().setFunc( function():void
			{
				leaveAttackScene();
				SystemSender.getInstance().CustomMsg( CustomToServerFlag.CLIENT_CUSTOMMSG_FB_END_CALCULATE );
				AttAckMsgCacheLogic.getInstance().sendAttackMsg();
				//要去判断是否杀死了boos，杀死了，才能发送弹副本界面
			}, againFight );
			
			//接收战报
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_SEND_FIGHT_REPORT), 	receiveFightReport);
			//竞技场别人战报
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_CHALLENGE_REPORT),	receivePkReport);
			//经营副本攻略战报
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_ELITE_FB_REPORT), 	receiveElipeReport);
			//发送掉落
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_SEND_ITEM_INFO),		receiveDropItem );
			
			//发送经验
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_SEND_FIGHT_PRIZE),	receivePvePrize );
			
			//发送pvp结算
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FIGHT_OVERUI_MSG),	receivePvpPrize );
			
			
			_model.addEventListener( String(CustomToClientFlag.SERVER_CUSTOMMSG_YLZG_ENTRY_BATTLESCENE), entryScene );
		}
		
		private function onKillFightClick( evt : MouseEvent ):void
		{
			_fightLogic.killFight();
			
			_killFightBtn.visible = false;
		}
		
		private function entryScene( e : CustomMsgEvent ):void
		{
//			WaitingForScene.start();
			_porte = e;
			AttAckMsgCacheLogic.getInstance().clear();
			
			_dropList = [];
//			_pvpPrize = [];
			
			if( _role == null )
			{
				_role			=	GameData.Role;
			}
			
			_role.killMove();
			
			_sceneManager.norSceneView.mouseChildren = _sceneManager.norSceneView.mouseEnabled = false;
			StageInfo.stage.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
			
			//告诉服务端
			SystemSender.getInstance().CustomMsg( CustomToServerFlag.CLIENT_CUSTOMMSG_PLAYER_MOVETO, 
				_role.x, _role.y, int( _role.x ), int( _role.y ) );
			
			_sceneModel = e.pList[ 0 ];
		
			if( !fighting )
			{
				initScene();
			}
		}
		
		private function initScene():void
		{
			if(WorldBossBloodUI.getInstance().isAutoAttack || FactionBossUI.getInstance().isAutoAttack )
			{
				return;
			}
			_model.dispatchEvent(new SceneEvent(SceneEvent.AttackSceneLoaded,[]));
			//进入场景
			_attackScene.enterScene( _sceneModel, _sceneModel != String( GameData.SceneModel ) );
//			_attackScene.enterScene( _sceneModel, true);
		}
		
		private function receivePvpPrize( e : CustomMsgEvent ):void
		{
//			_pvpPrize = [];
			if(e.pList.length>1)
				_pvpPrizeList .push(e.pList);
		}
		
		private function receiveDropItem( e : CustomMsgEvent ):void
		{
			_dropList = e.pList;
		}
		
		private function receivePvePrize( e : CustomMsgEvent ):void
		{
			_exp = e.pList[ 0 ];
			_experience =e.pList[1];
		}
		public function get Experience():int
		{
			return _experience;
		}
		private function getDropItem():Vector.<DropVo>
		{
			var dropVos : Vector.<DropVo> = new Vector.<DropVo>();
			
			for( var i : int = 1; i < _dropList.length; i+=2 )
			{
				dropVos.push( new DropVo( _dropList[ i ], genItemNum(_dropList[ i + 1 ] )) );
			}
			
			return dropVos;
		}
		
		private function genItemNum(amout:int):int
		{
			var num:int;
			if(amout)
			{
				num =amout;
			}
			else
			{
				num =1;
			}
			
			return num;
		}
		private function getPrize():Vector.<PrizeVo>
		{
			var prizeVos : Vector.<PrizeVo> = new Vector.<PrizeVo>();
			
			for each( var fightVo : FightInfoVo in _attackVo.fightVos )
			{
				if( fightVo.pos > 9 )continue;
				prizeVos.push( new PrizeVo( fightVo.name, fightVo.configID, _exp ,0,fightVo.type) );
			}
			return prizeVos;
		}
		/**
		 *竞技场战报 
		 * @param e
		 * 
		 */		
		private function receivePkReport(e:CustomMsgEvent):void
		{
			WarfareLogic.getInstance().isClick=true;
//			_attackType =1;
			receiveOtherFightReport(e,1);
		}
		/**
		 *精英战报 
		 * @param e
		 * 
		 */		
		private function receiveElipeReport(e:CustomMsgEvent):void
		{
			WarfareLogic.getInstance().isClick=true;
//			_attackType =0;
			receiveOtherFightReport(e,0);
		}
		//用于直接显示立即结束的战报
		private function receiveOtherFightReport( e:CustomMsgEvent,attacktype:int):void
		{
			if(e.pList.length ==1)return;
			_attackType = attacktype;
			if(fighting)
			{
				fightwarfter.push(function ():void
				{
					receiveOtherFightReport(e,attacktype)
				});
				return;
			}
			_isVideo = true;
			
			var pList : Array = e.pList;
			if( _fighting && 0 == pList[ 0 ] )
			{//在战斗，强行结束
				_fightLogic.killFight();
				
				_isKillFight = true;
			}
			
			fighting = true;
			
//			if( 1 != pList.length )
//			{
				_attackArr.push( [ e.pList[ 0 ], e.pList[ 1 ] ] );
//				return;
//			}
//			
			_attackArr.sortOn( "0", Array.NUMERIC );
			
			var attackStr : String = ""
			for( var i : int = 0; i < _attackArr.length; i++ )
			{
				attackStr += _attackArr[ i ][ 1 ];
			}
			
			_attackArr = [];
			
			_catchAttackStr = attackStr;
			
			attackStr=Base64.UnCompress(attackStr)
			
			_currWarfar =attackStr;
			if( _isKillFight )
			{
				setTimeout( function():void
				{
					initScene();
					enterFakeAttack(attackStr);
				},10000 );
				_isKillFight = false;
			}else
			{
				enterFakeAttack(attackStr)
			}
			UpNoticeLogic.getInstance().setVisible(false);
		}
		public var fightwarfter:Array=[];;
		private function receiveFightReport( e : CustomMsgEvent ):void
		{
			if(e.pList.length ==1)
			{
				_sceneManager.norSceneView.mouseChildren = _sceneManager.norSceneView.mouseEnabled = true;
				return;
			}
			if(fighting)
			{
				fightwarfter.push(function ():void
				{
					receiveFightReport(e)
				});
				return;
			}
			ArrowGuideLogic.getInstance().hideArrow();
			_isVideo = false;
//			WalkLogic.isShowLoading=false;
			if(WorldBossBloodUI.getInstance().isAutoAttack || FactionBossUI.getInstance().isAutoAttack)
			{
				_sceneManager.norSceneView.mouseChildren = _sceneManager.norSceneView.mouseEnabled = true;
				WalkManager.getInstance().walkLogic.isFight	=	false;
				roleResetPoint();
				return;
			}
			
			var pList : Array = e.pList;
			
			if( _fighting && 0 == pList[ 0 ] )
			{//在战斗，强行结束
				_fightLogic.killFight();
				
				_isKillFight = true;
			}
			
			fighting = true;
			WalkManager.getInstance().walkLogic.isFight	=	true;
			
//			if( 1 != pList.length )
//			{
			_catchAttackStr = e.pList[ 1 ];
				_attackArr.push( [ e.pList[ 0 ], Base64.UnCompress(e.pList[ 1 ] )] );
//				return;
//			}
			
			_attackArr.sortOn( "0", Array.NUMERIC );
			
			var attackStr : String = ""
			for( var i : int = 0; i < _attackArr.length; i++ )
			{
				attackStr += _attackArr[ i ][ 1 ];
			}
			
			_attackArr = [];
			
			if( _isKillFight )
			{
				setTimeout( function():void
				{
					initScene();
					
					enterAttackScene( attackStr ); 
				},10000 );
				_isKillFight = false;
			}else
			{
				enterAttackScene( attackStr );
			}
			UpNoticeLogic.getInstance().setVisible(false);
		}
		/**
		 * 进入战斗 
		 * @param val
		 * 
		 */		
		public function setAttackXML(val:String):void
		{
			_sceneModel	=	"12000100";
			initScene();
			_isKillFight	=	true;
			enterAttackScene( val );
		}
		/**
		 * 假战报专用入口 
		 * @param attackStr
		 * 
		 */		
		public function enterFakeAttack(attackStr:String):void
		{
			if( null != attackStr )
			{
				var _scene:String;
				_cloneXml = new XML(attackStr );
				IO.traceLog("假战报：",_cloneXml.toXMLString());
				_scene=_cloneXml.elements("FightInfo").attribute("sceneModel");
				
				_attackScene.enterScene( _scene, _scene != String( GameData.SceneModel ))
			}
			
			//加载技能
			_attackVo 	= 	new AttackVo( _cloneXml );
			if(_attackType !=0) //竞技场别人的战报
			{
				_attackVo.attackType =5;
			}
			
			AttackSkillManage.getInstance().loadSkills( getSkills( _attackVo ) , initFight );
		}
		
		
		
		
		/**
		 * 进入场景 
		 * @param e
		 */		
		public function enterAttackScene( attackStr : String ):void
		{
			if( null != attackStr )
			{
				_cloneXml = new XML( attackStr );
			}
			//加载技能
			_attackVo 	= 	new AttackVo( _cloneXml );
			AttackSkillManage.getInstance().loadSkills( getSkills( _attackVo ) , initFight );
		}
		
		private function getSkills( _attackVo : AttackVo ):Array
		{
			var skills : Array = [];
			
			//战斗技能
			var fightInfoVos : Vector.<FightInfoVo> = _attackVo.fightVos;
			for each( var fightInfoVo : FightInfoVo in fightInfoVos )
			{
				skills.push( fightInfoVo.skill );
			}
			
			var boutVos : Vector.<BoutVo> = _attackVo.boutVos;
			var buffers : Array = [];
			var damageVos : Vector.<DamageVo> = new Vector.<DamageVo>();
			
			for each( var boutVo : BoutVo in boutVos )
			{
				for each( var flowVo : FlowVo in boutVo.flowVos )
				{
					buffers.push( flowVo.skill );
					buffers.push( flowVo.buffer );
					for each( var damageVo : DamageVo in flowVo.damageVos )
					{
						buffers.push( damageVo.buffer );
					}
				}
			}
			
			var buffer : String;
			var bufferList : Array = [];
			for each( var buff : String in buffers )
			{
				if( buff == "" )continue;
				bufferList = buff.split( ";" );
				
				for( var i : int = 0; i < bufferList.length; i++ )
				{
					buffer = ( bufferList[ i ] as String ).split( ":" )[ 0 ];
					
					if( buffer != "" && skills.indexOf( buffer ) == -1 )
					{
						skills.push( buffer );
					}
				}
			}
			
			return skills;
		}
		
		private function onScenceEffectLoaded(val:DisplayObject, pList:Array):void
		{
			var bg : MovieClip = val as MovieClip;
			StageInfo.mainSpace.addChild( bg );
			bg.x  = _attackScene.x;
			bg.y  = _attackScene.y;
			
			bg.addFrameScript(bg.totalFrames-1,function():void
			{
				if( bg.parent )
				{
					bg.parent.removeChild( bg );
					bg.stop();
					bg = null;
				}
				
				var fightvos :Vector.<FightInfoVo> = _attackVo.fightVos;
				var fightpetvos :Vector.<FightPetInfoVo> = _attackVo.fightPetVos;
				_attackScene.createAttackPlayers( fightvos , fightpetvos);
				
				MainUIManager.getInstance().showAll();
				
				if(GameData.SceneType != GameDefine.SceneType_WorldBossScene)
				{
					StageInfo.storyMoveSpace.visible=false;
					SceneManager.getInstance().hideSceneView();
				}
				
				refreshRolePoint();
			});
		}
		
		private function initFight():void
		{
//			//进场景特效
			SwfLoader.StartLoad( ResPath.SWF + "switchScene.swf", null, onScenceEffectLoaded );
		}
		
		private function onStartFight( evt : Event ):void
		{
//			WaitingForScene.end();
			//是boos战
			StageInfo.stage.frameRate = 16;
			if( GameData.SceneType == GameDefine.SceneType_WorldBossScene)
			{
				AttackSceneLogic.getInstance().changeAttackSceneScale( _attackScene, .5 );
				
				StageInfo.attackSpace.addChild( _attackScene );
			}else
			{
				_sceneManager.hideSceneView();
				StageInfo.sceneSpace.addChild( _attackScene );
			}
			
			StageInfo.uiSpace.visible		=	true;

			
			
			StageInfo.effectSpace.visible = false;
			StageInfo.effectSpace.visible = true;
			
			StageInfo.effectSpace.mask = _effectMask;
			
			setTimeout( function():void
			{
				_fightLogic.startFight( _attackVo );
				if(CanShowCompleteBtn())
				{//vip5显示立即完成
					_attackScene.addChild( _killFightBtn );
					_killFightBtn.visible = true;
				}
				if( _isVideo )
				{//是录像，显示快速结束战斗按钮
					_attackScene.addChild( _killFightBtn );
					_killFightBtn.visible = true;
				}
			}, 1000 );
		}
		private function CanShowCompleteBtn():Boolean
		{
			var currlv:int=  _model.scene.Role.getVipLevel();
			if(currlv>=int(StaticIni.getIniVar("Attack_Need","showLv")))
			{
				return true;
			}
			return false;
		}
		private function againFight():void
		{
			_isVideo = true;
			
			_attackScene.clearPlayers();
			if( _attackVo.attackType ==5)
			{
				enterFakeAttack(_currWarfar)
			}
			else
			{
				_attackVo 	= 	new AttackVo( _cloneXml );
			
				initFight();
			}
			
		}
		
		public function isVideo():Boolean
		{
			return _isVideo;
		}
		/**
		 * 离开战斗场景场景 
		 * @param e
		 */			
		private function leaveAttackScene():void
		{
			deleteCurrPrizeLiset();
			
			WalkManager.getInstance().walkLogic.isReset	=	false;
			
			_sceneManager.norSceneView.mouseChildren = _sceneManager.norSceneView.mouseEnabled = true;
			
			removeAttackSceneView();
			
			StageInfo.mainSpace.mask = null;
			
			StageInfo.storyMoveSpace.visible=true;
			
			if(!StoryMoveUI.IsStory)
			{
				SceneManager.getInstance().showSceneView();
			}
			
			MainUIManager.getInstance().onStageReSize();
			

			
			StageInfo.effectSpace.mask = null;
			
			AttackSceneLogic.getInstance().resetAttackSceneScale( _attackScene );
			
			if(TopPlayerLogic.getInstance().isLevelUp)
			{
				_model.dispatchEvent( new RoleEffectEvent( RoleEffectEvent.LEVEL_UP ) );
				_model.dispatchEvent(new SoundEvent(SoundEvent.LEVEL_UP));
				TopPlayerLogic.getInstance().isLevelUp	=	false;
			}
			WalkManager.getInstance().walkLogic.isFight	=	false;
			UpNoticeLogic.getInstance().setVisible(true);
			fighting = false;
			if(fightwarfter.length>0)
			{
				entryScene(_porte);
				var fun:Function =fightwarfter.shift();
				fun.call();
			}
		}
		
		private function removeAttackSceneView():void
		{
			_attackScene.leaveScene();
			
			if( null != _attackScene.parent )
			{
				_attackScene.parent.removeChild( _attackScene );	
			}
		}

		public function get fighting():Boolean
		{
			return _fighting;
		}
		
		public function set fighting(value : Boolean):void
		{
			if( _fighting == value )return;
			
			
			_fighting = value;
		
			WalkLogic.Fight = _fighting;
		}
		
		private function refreshRolePoint():void
		{
			if( !_isKillFight )
			{
				if( 1 == _attackVo.attackType )
				{//副本PVE结算
					if( _attackVo.win )
					{
						if( GameData.SceneType == GameDefine.SceneType_WorldBossScene)
						{
							roleResetPoint();
						}
					}else
					{
						//人物回到复活点
						roleResetPoint();
						//怪物也要回到复活点
						npcResetPoint();
					}
				}else if( 3 == _attackVo.attackType || 2 == _attackVo.attackType)
				{// PVP结算
					if( GameData.SceneType!=GameDefine.SceneType_FactionScene)
					{
						roleResetPoint();
					}
				}
			}
		}
		
		private function getPrizeLiset():Array
		{
			var info:Array =[];
			for each(var i:Array in _pvpPrizeList)
			{
				var id:String = i[0];
				if(_attackVo.configID == id)
				{
					info = i.concat();
					info.shift();
					return info ;
				}
			}
			return info;
		}
		private function deleteCurrPrizeLiset():void
		{
			for (var i:String in _pvpPrizeList)
			{
				var id:String = _pvpPrizeList[int(i)][0];
				if(_attackVo.configID == id)
				{
					_pvpPrizeList.splice(int(i),1);
				}
			}
		}
		private function fightOver( evt : Event ):void
		{
			WarfareLogic.getInstance().isClick=false;
			WarfareLogic.getInstance().enable=true;
			_killFightBtn.visible = false;
			
			if( !_isKillFight )
			{
				_pvpPrize = getPrizeLiset();
				_pvpPrize.unshift( _attackVo.attackType );
				if( 1 == _attackVo.attackType )
				{//副本PVE结算
					if( _attackVo.win )
					{
						ActionResultLogic.getInstance().resultInfo( getDropItem(), getPrize() );
						
//						if( GameData.SceneType == GameDefine.SceneType_WorldBossScene)
//						{
//							roleResetPoint();
//						}
					}else
					{
//						_pvpPrize = _pvpPrizeList.shift();
//						if(_pvpPrize == null)
//						{
//							_pvpPrize = [];	
//						}
//						_pvpPrize.unshift( _attackVo.attackType );
						
						CurrencyResultLogic.getInstance().resultInfo( _attackVo.attackType,_pvpPrize, _attackVo.win );
						
//						_pvpPrize.shift();
						
//						//人物回到复活点
//						roleResetPoint();
//						//怪物也要回到复活点
//						npcResetPoint();
					}
				}
				else if(2 == _attackVo.attackType)
				{
					// 普通场景PVE结算
//					_pvpPrize = _pvpPrizeList.shift();
//					if(_pvpPrize == null)
//					{
//						_pvpPrize = [];	
//					}
//					_pvpPrize.unshift( _attackVo.attackType );
					
					CurrencyResultLogic.getInstance().resultInfo(_attackVo.attackType, _pvpPrize, _attackVo.win );
//					_pvpPrize.shift();
				}
				else if( 4 == _attackVo.attackType )
				{//无量玉壁结算
					if( _attackVo.win )
					{
//						_pvpPrize.shift()
						CurrencyResultLogic.getInstance().resultInfo(_attackVo.attackType, _pvpPrize, _attackVo.win );
						if( GameData.SceneType!=GameDefine.SceneType_FactionScene)
						{
							roleResetPoint();
						}
					}else
					{
//						_pvpPrize = _pvpPrizeList.shift();
//						if(_pvpPrize == null)
//						{
//							_pvpPrize = [];	
//						}
//						_pvpPrize.unshift( _attackVo.attackType );
						
						CurrencyResultLogic.getInstance().resultInfo( _attackVo.attackType,_pvpPrize, _attackVo.win );
					}
				}
				else if( 3 == _attackVo.attackType )
				{// PVP结算
//					_pvpPrize = _pvpPrizeList.shift();
//					_pvpPrize.unshift( _attackVo.attackType );
//					
					CurrencyResultLogic.getInstance().resultInfo(_attackVo.attackType, _pvpPrize, _attackVo.win );
//					_pvpPrize.shift();
					
				}
				//竞技场查看别人战报的结算
				else if(5 == _attackVo.attackType || 6  == _attackVo.attackType)
				{
//					_pvpPrize = _pvpPrizeList.shift();
//					_pvpPrize.unshift( _attackVo.attackType );
					CurrencyResultLogic.getInstance().resultInfo(_attackVo.attackType, _pvpPrize, _attackVo.win );
//					_pvpPrize.shift();
				}
				else if( 0 == _attackVo.attackType )
				{
					leaveAttackScene();
				}
			}else
			{
				_attackScene.clearPlayers();
			}
			
			_model.dispatchEvent( new CustomEvent( CustomEvent.ATTACK_STATUS, [ _attackVo.win ] ) );
			
			//发送战斗动画结束
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FIGHTING_ANI_OVER);
			
		}
		
		private function roleResetPoint():void
		{
			if( !_isVideo )
			{
				if( null == _role )
				{
					_role =	GameData.Role;
				}
				_role.resetPoint();
				
//				_sceneManager.norSceneView.backSceneView.x = 0;
			}
		}
		
		private function npcResetPoint():void
		{
			if( !_isVideo )
			{
				var npcs : Array = SceneManager.getInstance().norSceneView.scenePlayerLogic.playerDepts;
				
				for each( var npc : BasePlayerModel in npcs )
				{
					if( npc is RoleModel )
					{
						continue;
					}else if( npc is NpcModel )
					{
						( npc as NpcModel ).resetPoint();
					}
				}
			}
		}

		public function get attackScene():AttackSceneView
		{
			return _attackScene;
		}

		public function get fightLogic():FightLogic
		{
			return _fightLogic;
		}
	}
}
